import java.nio.channels.Pipe;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @User: vitobo
 * @Date: 2024-06-14
 * @Description: 一副扑克牌
 */

public class Pokers {
    public static final String[] SUITS = {"♥", "♠", "♣", "♦"};

    // 买一副扑克
    public static List<Poker> buyPokers(){
        List<Poker> pokerList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                Poker poker = new Poker(suit, j);
                pokerList.add(poker);
            }
        }
        return pokerList;
    }

    public static void swap(List<Poker> pokerList, int i, int j){
        Poker tmp = pokerList.get(i);
        pokerList.set(i, pokerList.get(j));
        pokerList.set(j, tmp);
    }
    // 洗牌
    public static void shuffle(List<Poker> pokerList){
        Random random = new Random();
        for (int i = pokerList.size()-1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(pokerList, i, index);
        }
    }

    public static void main(String[] args) {
        List<Poker> pokerList = buyPokers();
        System.out.println("买牌: " + pokerList);

        shuffle(pokerList);
        System.out.println("洗牌: " + pokerList);
    }


}
